using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic;
using YTS.Tools;
using System.ComponentModel;

namespace Test.ConsoleProgram.Algorithm.Work
{
    [TestDescription("工作逻辑: 计算产品操作数量")]
    public class Test_ProductOperationCount : AbsBaseTestItem
    {
        public override void OnTest()
        {
            // 269 - 156 = 113
            // IsCan(0, 269, 156) == 0,
            Assert.TestExe(MaxOperationCount, -9, 269, 156, 0);
            Assert.TestExe(MaxOperationCount, 9, 269, 156, 9);
            Assert.TestExe(MaxOperationCount, 100, 269, 156, 100);
            Assert.TestExe(MaxOperationCount, 160, 269, 156, 113);

            Assert.TestExe(MaxOperationCount, 0, 50, 150, 0);
            Assert.TestExe(MaxOperationCount, 1, 50, 150, 0);
            Assert.TestExe(MaxOperationCount, 48, 50, 150, 0);
            Assert.TestExe(MaxOperationCount, 50, 50, 150, 0);
        }

        /// <summary>
        /// 根据条件计算出最多的可操作数是多少
        /// </summary>
        /// <param name="BatchInventoryCount">单批次库存数</param>
        /// <param name="InventoryCount">总库存数</param>
        /// <param name="LockCount">总锁定数</param>
        /// <returns>最大可操作数</returns>
        public int MaxOperationCount(int BatchInventoryCount, int InventoryCount, int LockCount)
        {
            int canOperationCount = InventoryCount - LockCount;
            if (canOperationCount <= 0)
                return 0;
            BatchInventoryCount = BatchInventoryCount < 0 ? 0 : BatchInventoryCount;
            return BatchInventoryCount > canOperationCount ?
                canOperationCount : BatchInventoryCount;
        }
    }
}
